{% extends 'base.html' %}

{% block title %}{% if variable %}编辑{% else %}添加{% endif %}环境变量 - 环境变量管理{% endblock %}
{% block page_title %}{% if variable %}编辑环境变量{% else %}添加新环境变量{% endif %}{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">环境变量信息</h5>
            </div>
            <div class="card-body">
                <form method="post">
                    {% csrf_token %}
                    
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label for="{{ form.key.id_for_label }}" class="form-label">变量名</label>
                            {{ form.key }}
                            {% if form.key.errors %}
                            <div class="text-danger">{{ form.key.errors }}</div>
                            {% endif %}
                            <div class="form-text">只能包含字母、数字、下划线，且不能以数字开头</div>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="{{ form.value.id_for_label }}" class="form-label">变量值</label>
                        {{ form.value }}
                        {% if form.value.errors %}
                        <div class="text-danger">{{ form.value.errors }}</div>
                        {% endif %}
                    </div>

                    <div class="mb-3">
                        <label for="{{ form.description.id_for_label }}" class="form-label">描述</label>
                        {{ form.description }}
                        {% if form.description.errors %}
                        <div class="text-danger">{{ form.description.errors }}</div>
                        {% endif %}
                    </div>

                    <div class="mb-3">
                        <label for="{{ form.scope.id_for_label }}" class="form-label">生效范围</label>
                        {{ form.scope }}
                        {% if form.scope.errors %}
                        <div class="text-danger">{{ form.scope.errors }}</div>
                        {% endif %}
                        <div class="form-text">
                            <strong>全局</strong>: 写入系统配置文件，对所有用户生效（需要sudo权限）<br>
                            <strong>当前会话</strong>: 只在当前Web会话中生效（立即生效）<br>
                            <small class="text-warning">注意：全局变量修改后可能需要重新登录或重启服务才能完全生效</small>
                        </div>
                    </div>

                    <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                        <a href="{% url 'environment:list' %}" class="btn btn-secondary me-md-2">取消</a>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}